<html>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <head>
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.2.3/milligram.min.css">
  </head>
  <body class="container" style="padding-top: 3%;">
    <hr />

    <div class="row">
      <div class="column column-50">
        <label>当前账号：<span id="connaddr"></span>，余额:<span id="myeth"></span></label>
        <input id="contact" type="text" placeholder="合约地址" />

        <div>
          <button id="contactInit">初始化合约</button>
          <button id="mytime">当前时间</button>
        </div>

      <div class="row row-center">
        <input id="addr_1" type="text" placeholder="最大值" />
        <button id="btn_1">获取随机数</button>
      </div>

      <div class="row row-center">
        <input id="addr_2" type="text" placeholder="获奖数字" />
        <button id="btn_2">抽奖</button>
      </div>

        <br /><br />

      </div>
      <div class="column column-50">
        <label id="desc"></label>
        <div id="response" style="height:620px;width:600px;padding: 20px;overflow: auto; border: 1px solid #9b4dca; word-wrap: break-word">
          
        </div>
      </div>
    </div>

    <br /><br />

    <script type="text/javascript" src="ethjs.js"></script>
    <script type="text/javascript" src="ethjs-unit.js"></script>
    <script type="text/javascript" src="ethjs-util.js"></script>
    <script type="text/javascript">
      var eth = new Eth(web3.currentProvider);
      var el = function(id){ return document.querySelector(id); };

      window.onload = function(){
        SimpleStore = eth.contract(SimpleStoreABI).at(el("#contact").value);
        el('#response').innerHTML = "初始化成功";
      }

      var SimpleStoreABI = [{"constant":true,"inputs":[{"name":"array","type":"address[20]"},{"name":"ats","type":"uint256[20]"},{"name":"myaddr","type":"address"},{"name":"myamt","type":"uint256"}],"name":"selSortOut","outputs":[{"name":"","type":"address[20]"},{"name":"","type":"uint256[20]"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"max","type":"uint256"}],"name":"rand","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"signamt","type":"uint256"},{"name":"giveAmt","type":"uint256"}],"name":"isvalid","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"level","type":"uint256"},{"name":"tamt","type":"uint256"},{"name":"vip1","type":"uint256"},{"name":"vip2","type":"uint256"},{"name":"vip3","type":"uint256"}],"name":"caclVipAmt","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"amt","type":"uint256"},{"name":"total","type":"uint256"}],"name":"getYC","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"time","type":"uint256"}],"name":"getHour","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"array","type":"address[20]"},{"name":"myaddr","type":"address"}],"name":"getIndex1","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"array","type":"address[3]"},{"name":"ats","type":"uint256[3]"},{"name":"myaddr","type":"address"},{"name":"myamt","type":"uint256"}],"name":"selSortTop","outputs":[{"name":"","type":"address[3]"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"array","type":"address[3]"},{"name":"myaddr","type":"address"}],"name":"getIndex3","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"code","type":"uint256"}],"name":"getRand","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"one","type":"uint256"},{"name":"fif","type":"uint256"}],"name":"drawVip","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"time","type":"uint256"}],"name":"getHours","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"amt","type":"uint256"}],"name":"getEth","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"array","type":"address[100]"},{"name":"myaddr","type":"address"}],"name":"getIndex2","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"i","type":"uint256"},{"name":"amt","type":"uint256"}],"name":"caclReward","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"ats","type":"uint256[20]"}],"name":"getTotal","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"signamt","type":"uint256"}],"name":"out","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"array","type":"address[100]"},{"name":"ats","type":"uint256[100]"},{"name":"myaddr","type":"address"},{"name":"myamt","type":"uint256"}],"name":"selSortBase","outputs":[{"name":"","type":"address[100]"},{"name":"","type":"uint256[100]"}],"payable":false,"stateMutability":"pure","type":"function"}];
      var SimpleStore;
      el("#contactInit").addEventListener('click', function(){
          SimpleStore = eth.contract(SimpleStoreABI).at(el("#contact").value);
          el('#response').innerHTML = "初始化成功";
      });
      
      eth.accounts().then(function(accounts) {
          var myAddr = accounts[0];
          el("#connaddr").innerHTML = myAddr;
          if(myAddr){
            eth.getBalance(myAddr).then(function(valueStored){
              el('#myeth').innerHTML = String(ethUnit.fromWei(valueStored,'ether'));
            });
          }
      });

      el('#mytime').addEventListener('click', function(){
        el("#desc").innerHTML = "获取当前时间";
        el('#response').innerHTML = '';
        SimpleStore.mytime().then(function(setTxHash){
            el('#response').innerHTML = String(setTxHash[0]);
          });
      });

      el('#btn_1').addEventListener('click', function(){
        el("#desc").innerHTML = "获取随机数";
        el('#response').innerHTML = '';
        var max = el("#addr_1").value;
        SimpleStore.rand(max).then(function(setTxHash){
            el('#response').innerHTML = String(setTxHash[0]);
          });
      });

      el('#btn_2').addEventListener('click', function(){
        el("#desc").innerHTML = "指定数字抽奖";
        el('#response').innerHTML = '';
        var max = el("#addr_2").value;
        SimpleStore.getRand(max).then(function(setTxHash){
            el('#response').innerHTML = String(ethUnit.fromWei(setTxHash[0],'ether'));
          });
      });
    </script>
  </body>
</html>
